home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Presentations / Presentations ’93 / Macintosh as Internet Server ƒ / inetd / Libraries / DaemonApp / UFailure.a < prev    next >
Encoding:
Text File  |  1993-03-17  |  4.9 KB  |  169 lines  |  [TEXT/MPS ]

  1. ;=============================================================================
  2. ; Failure Handler Assembly Routines
  3. ;
  4. ; KNOWN LIMITATIONS
  5. ;
  6. ; Copyright © 1984-1992 Apple Computer, Inc.  All rights reserved.
  7. ;
  8. ; when       who    what
  9. ; -------- ---- --------------------------------------------------------------
  10. ; 88.07.28 srf    add header and includes for Macros
  11. ; ----------------------------------------------------------------------------
  12.  
  13.                 Blanks        On
  14.                 String        AsIs
  15.                 Case        On
  16.  
  17.                 Print        Off
  18.                 
  19.                 Include        'Hack.a'
  20.                 
  21.                 Include     'Macros.a'
  22.  
  23.                 LOAD        'ProgStrucMacs.d'
  24.                 LOAD        'FlowCtlMacs.d'
  25.                 Print        On
  26.  
  27. ;---------------------------------------------------------------------------------------------------
  28.             
  29. nSavedRegs        Equ         12
  30.  
  31. ; flags to indicate which type of handler is stored in the FailInfo record
  32. kPascalProcCall    Equ            0
  33. kCFuncCall        Equ            1
  34.  
  35. ; flag to indicate whether the failure handler has been installed by Try or CatchFailures
  36. kInstalled        Equ            1
  37.  
  38.                 Seg         'MAFailureRes'
  39. ;-------------------------------------------------------------------
  40. ;PROCEDURE CatchFailures(VAR fi: FailInfo; PROCEDURE Handler(e: INTEGER; m: LONGINT)); EXTERNAL;
  41. ;-------------------------------------------------------------------
  42. CATCHFAILURES    Proc        Export
  43.                 DATA
  44.                 Import        gTopHandler:Data
  45.                 CODE
  46.  
  47. A6Link            Equ         4                        ; static link which the Pascal compiler
  48.                                                     ; automatically pushes on the stack after
  49.                                                     ; pushing a ProcPtr ("PROCEDURE Handler")
  50. handler         Equ         A6Link + 4                ; the ProcPtr ("PROCEDURE Handler")
  51. fiVAR            Equ         handler + 4
  52. parmSize        Equ         fiVAR + 4 - A6Link
  53.  
  54.                 Head
  55.                 MoveA.L        fiVAR(SP),A0            ; get pointer to FailInfo block
  56.         
  57.                 MoveM.L     A2-A7/D2-D7,(A0)        ; save All regs first
  58.                 AddA         #nSavedRegs*4,A0        ; advance pointer by # bytes regs
  59.                 
  60.                 Clr.L        (A0)+                    ; set flags field and error field
  61.                                                     ;     set flags field: 0 is for CatchFailures 
  62.                                                     ;     clear error field
  63.  
  64.                 Clr.L        (A0)+                    ; clear message field
  65.         
  66.                 Lea         A6Link(SP),A1            ; save the A6Link And Proc ptr
  67.                 Move.L        (A1)+,(A0)+             ; save the A6Link
  68.                 Move.L        (A1)+,(A0)+             ; save the Proc ptr
  69.         
  70.                 Move.L        gTopHandler(A5),(A0)+    ; Link the FailInfo into the LIST
  71.                 Move.L        fiVAR(SP),gTopHandler(A5)
  72.     If    qDebug Then
  73.                 Move.L        (SP),(A0)+                ; remember the caller's PC
  74.                 Move.W        #kInstalled, (A0)+        ; remember that we've been installed
  75.     EndIf
  76.  
  77. exit
  78.                 MoveA.L        (SP)+,A0
  79.                 AddA.L        #parmSize,SP
  80.                 Jmp         (A0)
  81.                 Tail        CATCHFAILURES
  82.         
  83. ;-------------------------------------------------------------------
  84. ;FUNCTION Try(VAR fi: FailInfo): BOOLEAN; EXTERNAL C;
  85. ;-------------------------------------------------------------------
  86. Try                Proc        Export
  87.                 DATA
  88.                 Import        gTopHandler:Data
  89.                 CODE
  90.  
  91. fiVAR            Equ          4
  92. parmSize        Equ         fiVAR
  93.  
  94.                 Head
  95.                 MoveA.L        fiVAR(SP),A0            ; get pointer to FailInfo block
  96.         
  97.                 MoveM.L     A2-A7/D2-D7,(A0)        ; save All regs first
  98.                 AddA         #nSavedRegs*4,A0        ; advance pointer by # bytes regs
  99.                 
  100.                 Move.L        #$00010000,(A0)+        ; Set flags field and error field.
  101.                                                     ;     Set flags field: 1 is for Try 
  102.                                                     ;     Clear error field
  103.  
  104.                 Clr.L        (A0)+                    ; clear message field
  105.         
  106.                 Clr.L        (A0)+                     ; clear the A6Link.  Not used with Try
  107.                 Move.L        (SP), (A0)+             ; save the return address as the continuation ptr
  108.         
  109.                 Move.L        gTopHandler(A5),(A0)+    ; Link the FailInfo into the LIST
  110.                 Move.L        fiVAR(SP),gTopHandler(A5)
  111.     If    qDebug Then
  112.                 Move.L        (SP),(A0)+                ; remember the caller's PC
  113.                 Move.W        #kInstalled, (A0)+        ; remember that we've been installed
  114.     EndIf
  115.  
  116. exit
  117.                 MoveQ        #1,D0                    ; Boolean true, enter the conditioned block of code to try
  118.                 RTS
  119.                 Tail        Try
  120.         
  121.  
  122.                 Seg         'MAFailureRes'
  123. ;-------------------------------------------------------------------
  124. ;PROCEDURE DoFailure(pf: PFailInfo); EXTERNAL;
  125. ;-------------------------------------------------------------------
  126. DOFAILURE        Proc        Export
  127.                 Import        FAILURE
  128.  
  129. pf                Equ         4
  130.  
  131.                 Head
  132.                 MoveA.L        pf(SP),A0                ; get pointer to FailInfo
  133.  
  134.                 MoveM.L     (A0)+,A2-A7/D2-D7        ; restore regs (can't use A7 anymore)
  135.         
  136.                 CmpI.W        #kPascalProcCall,(A0)+
  137.                 Beq.S        PascalProcCall
  138.                 Clr.W        D0                        ; Boolean false, enter the conditioned block of failure code
  139.                 Addq        #4, A7                    ; bump stack b/c of return address in Try()
  140.                 MoveA.l        10(A0),A0
  141.                 Jmp            (A0)
  142.  
  143. PascalProcCall
  144.                 Move.W        (A0)+,D0                ; get error
  145.                 Move.L        (A0)+,D1                ; And message
  146.  
  147.                 MoveM.L     D0/D1,-(SP)             ; save for later use
  148.         
  149.                 Move.W        D0,-(SP)
  150.                 Move.L        D1,-(SP)                ; parameters to failure handler
  151.                 
  152.                 Move.L        (A0)+,D0                ; check the A6Link
  153.                 Beq.S        @1                        ; If NIL Then don't pass it
  154.                 Move.L        D0,-(SP)                ; Else Do pass it
  155. @1
  156.                 MoveA.L        (A0)+,A0                ; get address of failure handler
  157.         
  158.                 Jsr         (A0)                    ; call failure handler
  159.  
  160.                 MoveM.L     (SP)+,D0/D1             ; get error & message back
  161.                 Move.W        D0,-(SP)
  162.                 Move.L        D1,-(SP)                ; parameters to Failure
  163.                 Jsr         FAILURE
  164.                 
  165.                 ; should Not return
  166.                 Tail    DOFAILURE
  167.         
  168.                 End
  169.